//
//  XQToastView.swift
//  Spark Peso
//
//  Created by 小琦 on 2025/1/28.
//

import UIKit

class XQToastView: UIView {

    init(message : String,
         config : XQToastConfig) {
        super.init(frame: CGRect.zero)
        makeUI(message: message, config: config);
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func makeUI(message : String,config : XQToastConfig) {
        let containerView = UIView()
        containerView.backgroundColor = config.bgColor
        containerView.layer.cornerRadius = config.cornerRadius
        addSubview(containerView)
        
        containerView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        let view = XQCommonView(message: message,
                              image: nil)
        
        view.messageLb.textColor = config.messageColor
        view.messageLb.font = config.messageFont

        containerView.addSubview(view)

        view.snp.makeConstraints { (make) in
            make.top.left.equalToSuperview().offset(config.padding)
            make.bottom.right.equalToSuperview().offset(-config.padding)
            make.width.lessThanOrEqualTo(config.toastMaxWidth)
            make.height.lessThanOrEqualTo(config.toastMaxHeight)
        }
    }
}
